<?php if (!defined("_ECRIRE_INC_VERSION")) return; if (class_exists('PdkFieldsContainer')) return;
/**
 * SPIP Plugin Development Kit
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage pdk
 * @category   outils
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/Developmet-Kit
 * @version    1.0.0
 */

include_spip('classes/pdk_model');
include_spip('inc/session');
/** 
 *  This class helps to work with fields in forms
 *
 *  @author Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 */
class PdkFieldsContainer {
    /**
     *  Session variable, in wich fields are stored
     */
    private $session_variable;
        
    /**
     *  Конструктор
     *  @param string $form_name Имя формы. Нужно для того, чтобы поля разных форм не накладывались.
     */
    public function __construct($form_name = 'default') {        
        $this->session_variable = 'PdkFieldsContainer_fields'.$form_name;
    }
    
    /**
     *  Add field to session
     */
    public function AddField($name, $value) {
        $fields = session_get($this->session_variable);        
        if (!isset($fields))
            $fields = array();
        $fields[$name] = $value;
        session_set($this->session_variable, $fields);
    }
    
    /**
     *  Get all fields from session
     */
    public function GetFields() {
        return session_get($this->session_variable); 
    }
    
    /**
     *  Clear all fields in session
     */
    public function ClearFields() {
        session_set($this->session_variable);
    }
}
?>